<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key">


  <!-- Define decimal format -->
  <xsl:decimal-format name="pt-br-Decimal" grouping-separator="." digit="#" zero-digit="0" decimal-separator="," />

  <!-- StyleSttings ********************************************  -->
  <!-- Defines the style attributes for the document.             -->
  <!-- ***********************************************************-->
  <xsl:template name="StyleSettings">
    <FlowDocument.Resources>

      <SolidColorBrush x:Key="AlertBackgroundBrush" Color="#FCEFB6"/>

      <SolidColorBrush x:Key="AlertBrush" Color="#EE6C0A"/>

      <Style x:Key="AlertBorder" TargetType="Border">
        <Setter Property="Background" Value="{{StaticResource AlertBackgroundBrush}}"/>
        <Setter Property="BorderBrush" Value="{{StaticResource AlertBrush}}"/>
        <Setter Property="CornerRadius" Value="3"/>
        <Setter Property="Margin" Value="0,6,0,6"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="TextBlock.Foreground" Value="{{StaticResource AlertBrush}}"/>
        <Setter Property="TextBlock.FontSize" Value="20"/>
        <Setter Property="Padding" Value="3"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
      </Style>


      <Style x:Key="TaskAlertCell" TargetType="TableCell">
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="Background" Value="Yellow"/>
        <Setter Property="Foreground" Value="Red"/>
      </Style>

      

      <Style x:Key="BacklogItemDone" TargetType="Span">
        <Setter Property="Background" Value="LightGreen"/>
        <Setter Property="Foreground" Value="DarkGreen"/>
      </Style>

      <Style x:Key="BacklogItemWorking" TargetType="Span">
        <Setter Property="Background" Value="Yellow"/>
        <Setter Property="Foreground" Value="Orange"/>
      </Style>

      <Style x:Key="BacklogItemRequired" TargetType="Span">
        <Setter Property="Background" Value="Pink"/>
        <Setter Property="Foreground" Value="Red"/>
      </Style>

      <Style x:Key="BacklogItemCanceled" TargetType="Span">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Foreground" Value="Black"/>
      </Style>

      <Style TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="10"/>
      </Style>

      <Style x:Key="ParagraphCenter" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="10"/>
        <Setter Property="TextAlignment" Value="Center"/>
      </Style>


      <Style x:Key="BigParagraph" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="22"/>
        <Setter Property="FontWeight" Value="Bold"/>
      </Style>
      <Style x:Key="BigParagraphCenter" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="22"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="TextAlignment" Value="Center"/>
      </Style>

      <Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="10"/>
      </Style>

      <Style x:Key="TitleParagraph" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Margin" Value="0,20,0,5"/>
      </Style>

      <Style x:Key="SubTitleParagraph" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="12"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Margin" Value="0,10,0,5"/>
      </Style>

      <Style x:Key="SubTitleParagraphCenter" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="12"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Margin" Value="0,10,0,5"/>
        <Setter Property="TextAlignment" Value="Center"/>
      </Style>

      <Style x:Key="TotalSumParagraph" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Margin" Value="0,10,5,5"/>
        <Setter Property="TextAlignment" Value="Right"/>
      </Style>

      <Style x:Key="SumItemParagraph" TargetType="Paragraph">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="10"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="TextAlignment" Value="Right"/>
      </Style>

      <Style x:Key="HeaderRow" TargetType="TableRow">
        <Setter Property="Background" Value="Black"/>
        <Setter Property="Foreground" Value="White"/>        
      </Style>

      <Style x:Key="GroupRow" TargetType="TableRow">
        <Setter Property="Background" Value="#DDDDDD"/>
        <Setter Property="Foreground" Value="Black"/>
      </Style>

      <Style TargetType="Table">
        <Setter Property="CellSpacing" Value="0"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="Margin" Value="0,0,0,5"/>
      </Style>

      <Style TargetType="TableCell">
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>

      <Style x:Key="NormalCell" TargetType="TableCell">
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>

      <Style x:Key="RightBorderCell" TargetType="TableCell">
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,2,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>
      <Style x:Key="RightBorderCellOnly" TargetType="TableCell">
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0,0,2,0"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>


      <Style x:Key="PageHeaderTable" TargetType="Table">
        <Setter Property="Background" Value="#DDDDDD"/>
      </Style>

      <Style x:Key="HeaderCell" TargetType="TableCell">
        <Setter Property="Background" Value="Black"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>

      <Style x:Key="GroupCell" TargetType="TableCell">
        <Setter Property="Background" Value="#DDDDDD"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
      </Style>

      <Style x:Key="NoBorderTable" TargetType="Table">
        <Setter Property="CellSpacing" Value="0"/>
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="BorderThickness" Value="0,0,0,0"/>
        <Setter Property="Padding" Value="0,0,0,0"/>
        <Setter Property="Margin" Value="0,0,0,0"/>
      </Style>

      <Style x:Key="NoBorderCell" TargetType="TableCell">
        <Setter Property="BorderThickness" Value="0,0,0,0"/>
        <!--<Setter Property="Padding" Value="0,0,0,0"/>-->
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="SingleLineCell" TargetType="TableCell">
        <Setter Property="BorderThickness" Value="0,0,0,1"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
        <Setter Property="BorderBrush" Value="Gray"/>
      </Style>

      <Style x:Key="DoubleLineCell" TargetType="TableCell">
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="BorderThickness" Value="0,0,0,3"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="AlternateCell1" TargetType="TableCell">
        <Setter Property="Background" Value="#FFFFFF"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="AlternateCell2" TargetType="TableCell">
        <Setter Property="Background" Value="#EEEEEE"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="CurrentCell" TargetType="TableCell">
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Background" Value="Yellow"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="BacklogItemDoneCell" TargetType="TableCell">
        <Setter Property="Background" Value="#77A44C"/>
        <Setter Property="Foreground" Value="#416000"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>



      <Style x:Key="BacklogItemWorkingCell" TargetType="TableCell">        
        <Setter Property="Background" Value="#f3d775"/>
        <Setter Property="Foreground" Value="#d7aa0e"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      

      <Style x:Key="BacklogItemRequiredCell" TargetType="TableCell">
        <Setter Property="Background" Value="#d47777"/>
        <Setter Property="Foreground" Value="#820909"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>

      <Style x:Key="BacklogItemCanceledCell" TargetType="TableCell">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="BorderThickness" Value="0.5,0.5,0.5,0.5"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="Padding" Value="5,3,5,3"/>
      </Style>



    </FlowDocument.Resources>
  </xsl:template>

  <xsl:template name="SprintAndPlanStatus">
    <xsl:param name="context" select="/ProjectDataSet"/>
    <TextBlock FontFamily="Arial" FontSize="10" Margin="0,5,0,0">
      <xsl:choose>
        <xsl:when test="$currentSprintNumber">
          <xsl:value-of select="$currentSprintNumber"/>&#186; Sprint
        </xsl:when>
        <xsl:otherwise>
          No Sprints Running
        </xsl:otherwise>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="$context/Project/Baseline &gt; 0">
          (<xsl:value-of select="$context/Project/Baseline"/>&#186; Plan)
        </xsl:when>
        <xsl:otherwise>
          (Proposal Plan)
        </xsl:otherwise>
      </xsl:choose>
    </TextBlock>
  </xsl:template>

  <xsl:template name="Header">
    <xsl:param name="type" select="'BackLog'"/>    
    <xsl:param name="context" select="/ProjectDataSet"/>
    <xsl:param name="emmitionDateString" select="$context/General/TodayString"/>
    <xsl:param name="isProjectHeader" select="1"/>
    <Table Style="{{StaticResource NoBorderTable}}" Margin="0,0,0,0">
      <Table.Columns>
        <TableColumn />
        <TableColumn Width="200"/>
      </Table.Columns>
      <TableRowGroup>
        <TableRow>
          <TableCell Style="{{StaticResource NoBorderCell}}">

            <BlockUIContainer>
              <Border CornerRadius="5,5,5,5" Background="#EEEEEE" BorderBrush="#AAAAAA" BorderThickness="1" Padding="5" MinHeight="100">
                <TextBlock FontFamily="Arial">
                  <TextBlock FontFamily="Arial" FontSize="24" Margin="0,2,0,0" >
                    <xsl:value-of select="$type"/>
                  </TextBlock>
                  <xsl:if test="$isProjectHeader">
                    <LineBreak/>
                    <TextBlock FontSize="15" Margin="0,5,0,0">
                      <xsl:value-of select="$context/Project/ProjectName"/> [<xsl:value-of select="$context/Project/ProjectNumber"/>]
                    </TextBlock>
                    <TextBlock FontSize="10" Margin="0,5,0,0">
                      ,
                      <xsl:value-of select="$context/Project/ClientName"/>
                    </TextBlock>
                    <LineBreak/>
                    <xsl:call-template name="SprintAndPlanStatus"/>
                    <LineBreak/>
                    <TextBlock FontFamily="Arial" FontSize="10" Margin="0,5,0,0">
                      Scrum Master(s):
                      <xsl:for-each select="$context/Project/ProjectRole[UnitName=$context/Project/BacklogItemUnit[Type=1]/UnitName]">
                        <xsl:sort select="ContactName"/>
                        <xsl:value-of select="ContactName"/>
                        <xsl:if test="position() != last()">, </xsl:if>
                      </xsl:for-each>
                    </TextBlock>
                  </xsl:if>
                  
                </TextBlock>
              </Border>
            </BlockUIContainer>
            <Paragraph Margin="0,5,0,0">
              <xsl:value-of select="$emmitionDateString"/>
            </Paragraph>

          </TableCell>
          <TableCell Style="{{StaticResource NoBorderCell}}">
            <BlockUIContainer>
              <Image HorizontalAlignment="Right" Source="{$ServerURL}/FactoryService/Images/Company/logo.jpg" Width="150"/>
            </BlockUIContainer>
          </TableCell>
        </TableRow>
      </TableRowGroup>
    </Table>

  </xsl:template>


  <xsl:template name="SprintHeader">
    <xsl:param name="type" select="'BackLog'"/>
    <xsl:param name="sprintNumber"/>        
    <xsl:param name="context" select="/ProjectDataSet"/>
    <xsl:param name="emmitionDateString" select="$context/General/TodayString"/>
    <Table Style="{{StaticResource NoBorderTable}}" Margin="0,0,0,0">
      <Table.Columns>
        <TableColumn />
        <TableColumn Width="200"/>
      </Table.Columns>
      <TableRowGroup>
        <TableRow>
          <TableCell Style="{{StaticResource NoBorderCell}}">

            <BlockUIContainer>
              <Border CornerRadius="5,5,5,5" Background="#EEEEEE" BorderBrush="#AAAAAA" BorderThickness="1" Padding="5">
                <StackPanel Orientation="Vertical">
                  <StackPanel Orientation="Horizontal">
                    <xsl:if test="$sprintNumber &gt; 0">
                      <Border CornerRadius="5,5,5,5" Background="#000000" BorderBrush="#AAAAAA" BorderThickness="1" Padding="4">
                        <TextBlock FontFamily="Arial" FontSize="20" Foreground="#FFFFFF" FontWeight="Bold">
                          <xsl:value-of select="$sprintNumber"/>&#186;
                        </TextBlock>
                      </Border>
                    </xsl:if>

                    <TextBlock FontFamily="Arial" FontSize="24" Margin="3,2,0,0" >
                      Sprint <xsl:value-of select="$type"/>

                      <xsl:if test="$sprintNumber &gt; 0">
                        <TextBlock FontFamily="Arial" FontSize="15" Margin="10,0,0,0">
                          (<xsl:value-of select="$context/Project/Sprint[SprintNumber=$sprintNumber]/StartDateString"/>
                          - <xsl:value-of select="$context/Project/Sprint[SprintNumber=$sprintNumber]/ExpirationDateString"/>)
                        </TextBlock>
                      </xsl:if>

                    </TextBlock>

                  </StackPanel>
                  <TextBlock FontFamily="Arial" FontSize="15" Margin="0,5,0,0">

                    <xsl:value-of select="$context/Project/ProjectName"/> [<xsl:value-of select="$context/Project/ProjectNumber"/>],
                    <TextBlock FontFamily="Arial" FontSize="10">
                      <xsl:value-of select="$context/Project/ClientName"/>
                    </TextBlock>

                  </TextBlock>
                  <xsl:call-template name="SprintAndPlanStatus"/>

                  <TextBlock FontFamily="Arial" FontSize="10" Margin="0,5,0,0">
                    Scrum Master(s):
                    <xsl:for-each select="$context/Project/ProjectRole[UnitName=$context/Project/BacklogItemUnit[Type=1]/UnitName]">
                      <xsl:sort select="ContactName"/>
                      <xsl:value-of select="ContactName"/>
                      <xsl:if test="position() != last()">, </xsl:if>
                    </xsl:for-each>
                  </TextBlock>







                </StackPanel>
              </Border>
            </BlockUIContainer>
            <Paragraph Margin="0,5,0,0">
              <xsl:value-of select="$emmitionDateString"/>
            </Paragraph>

          </TableCell>
          <TableCell Style="{{StaticResource NoBorderCell}}">
            <BlockUIContainer>
              <Image HorizontalAlignment="Right" Source="{$ServerURL}/FactoryService/Images/Company/logo.jpg" Width="150"/>
            </BlockUIContainer>
          </TableCell>
        </TableRow>
      </TableRowGroup>
    </Table>

  </xsl:template>

</xsl:stylesheet>

